package com.io.nio2;

/**
 * @author hjj
 * @create 2019-11-24 18:44
 */
public class NIOServer {
    private static Integer DEFAULT_PORT = 8890;
    private static NIOServerHandler nioServerHandler;

    public static void start() {
        start(DEFAULT_PORT);
    }

    public static void stop() {
        if (nioServerHandler != null) nioServerHandler.stop();
    }

    public static synchronized void start(int port) {
        if (nioServerHandler != null) nioServerHandler.stop();
        nioServerHandler = new NIOServerHandler(port);
        new Thread(nioServerHandler, "NIOServerHandler").start();
    }
}
